package com.example.tys.daggermvp;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.example.tys.daggermvp.mvp.base.BaseModule;
import com.example.tys.daggermvp.mvp.base.BasePresenter;
import com.example.tys.daggermvp.mvp.base.BaseView;

import javax.inject.Inject;

import dagger.android.support.DaggerAppCompatActivity;

/**
 * 继承DaggerAppCompatActivity, Dagger注入
 *
 * @author tys
 * @date 2018/4/17
 */

@SuppressLint("Registered")
public class BaseActivity<P extends BasePresenter, V extends BaseView, D extends BaseModule> extends DaggerAppCompatActivity {
    @Inject
    protected P mPresenter;

    @Inject
    protected D mDataModule;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter.takeData(mDataModule);
    }


    @Override
    protected void onResume() {
        super.onResume();
        if (this instanceof BaseView) {
            mPresenter.takeView((V) this);
        }
    }

    @Override
    protected void onDestroy() {
        mPresenter.drop();
        super.onDestroy();
    }


}
